﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Moq;

namespace MoqContrib.AutoMock.Tests.AutoMockingContainers
{
	#region Types used for testing
	class EmptyHelper : AutoMockHelper
	{

		public override T CreateTestSubject<T>()
		{
			throw new NotImplementedException();
		}

		protected override void RegisterInstance(Type type, object instance)
		{
		}

		protected override void RegisterInstance(Type type, string key, object instance)
		{
		}

		protected override void RegisterInstance(Type[] services, object instance)
		{
		}
	}
	#endregion

	[TestFixture]
	class WhenDoingSetupsAndVerifys 
	{
		private EmptyHelper _helper;
		[SetUp]
		public void Given()
		{
			_helper = new EmptyHelper();
		}

		[Test]
		public void I_can_setup_voidvoid_directly()
		{
			bool wasCalled = false;
			_helper.Setup<IService>(x => x.Meth()).Callback(() => wasCalled = true);
			_helper.Of<IService>().Meth();
			Assert.That(wasCalled);
		}

		[Test]
		public void I_can_setup_func_directly()
		{
			_helper.Setup<IService>(x => x.Func()).Returns("foo");
			var result = _helper.Of<IService>().Func();
			Assert.That(result, Is.EqualTo("foo"));
		}

		[Test]
		public void I_can_verify_action()
		{
			_helper.Of<IService>().Meth();
			_helper.Verify<IService>(x => x.Meth());
		}
		[Test]
		public void I_can_verify_action_with_times()
		{
			_helper.Of<IService>().Meth();
			_helper.Verify<IService>(x => x.Meth(), Times.Once());
		}
		[Test]
		public void I_can_verify_action_with_message()
		{
			_helper.Of<IService>().Meth();
			_helper.Verify<IService>(x => x.Meth(), "blah");
		}
		[Test]
		public void I_can_verify_action_with_times_and_message()
		{
			_helper.Of<IService>().Meth();
			_helper.Verify<IService>(x => x.Meth(), Times.Once(), "blah");
		}


		[Test]
		public void I_can_verify_func()
		{
			_helper.Of<IService>().Func();
			_helper.Verify<IService>(x => x.Func());
		}
		[Test]
		public void I_can_verify_func_with_times()
		{
			_helper.Of<IService>().Func();
			_helper.Verify<IService>(x => x.Func(), Times.Once());
		}
		[Test]
		public void I_can_verify_func_with_message()
		{
			_helper.Of<IService>().Func();
			_helper.Verify<IService>(x => x.Func(), "blah");
		}
		[Test]
		public void I_can_verify_func_with_times_and_message()
		{
			_helper.Of<IService>().Func();
			_helper.Verify<IService>(x => x.Func(), Times.Once(), "blah");
		}
	}
}
